package projectx.core.dao;

import java.sql.SQLException;


public class ExceptionHandler {

	public static final int NOTFOUND = 0;

	public static final int NORMAL = 1;

	public static final int MULTIFOUND = 2;

	public static final int NOTUPDATED = 3;

	public static final int MULTIUPDATED = 4;

	public static final int UNKNOWN = 5;

	private static ExceptionHandler handler = new ExceptionHandler();

	private ExceptionHandler() {
	}

	public static ExceptionHandler getHandler() {
		return handler;
	}

	public static void setHandler(ExceptionHandler exHandler) {
		handler = exHandler;
	}

	public void handleQueryException(Exception e, int state)
			throws DataAccessException {
		if (e instanceof SQLException) {
			throw new DataAccessException((SQLException) e);
		}
		throw new DataAccessException(e);
	}

	public void handleUpdateException(Exception e, int state)
			throws DataAccessException {
		if (e instanceof SQLException) {
			if (((SQLException) e).getErrorCode() == -803) {
				throw new DuplicatedException((SQLException) e);
			}
			throw new DataAccessException((SQLException) e);
		}
		throw new DataAccessException(e);
	}
}
